/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meluk.billboard.beans.controller;

import java.util.Locale;

import org.hibernate.SessionFactory;
import org.meluk.billboard.jpa.StatisticPlayer;
import org.meluk.billboard.jpa.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author AMelnyk
 *
 */
@Controller
@RequestMapping("/test")
public class HelloWorldController {

    public HelloWorldController() {
        System.out.println("HelloWorldController constructor");
    }
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private SessionFactory sessionFactory;

    @Transactional
    @RequestMapping("/helloWorld")
    @ResponseBody
    public String helloWorld() {
        User user = new User();
        user.setName("Vasya");
        user.setPassword("Vasyaspassword");
        user.setAge(18);
        getSessionFactory().getCurrentSession().save(new User());
        return String.format("Hello World %s 1", "");

    }

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    public void setApplicationContext(ApplicationContext applicationContext) {
        this.applicationContext = applicationContext;
    }
}
